/*
 * Copyright 2009 Codecarpet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.codecarpet.fbconnect;

import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;

public class FBFeedDialog extends FBDialog {

    private static final String PUBLISH_URL = "http://www.facebook.com/connect/prompt_feed.php";

    private String mMessagePrompt;
    private String mAttachment;
    private String mActionLinks;
    private String mTargetId;

    public FBFeedDialog(Activity context, FBSession session, String messagePrompt, String attachment, String actionLinks, String targetId) {
        super(context, session);
        mMessagePrompt = messagePrompt;
        mAttachment = attachment;
        mActionLinks = actionLinks;
        mTargetId = targetId;
    }

    private void loadExtendedPermissionPage() {
        Map<String, String> getParams = new HashMap<String, String>();
        getParams.put("display", "touch");
        getParams.put("callback", "fbconnect://success");
        getParams.put("cancel", "fbconnect://cancel");
        
        Map<String, String> postParams = new HashMap<String, String>();

        postParams.put("api_key", mSession.getApiKey());
        postParams.put("session_key", mSession.getSessionKey());
        postParams.put("preview", "1");
        postParams.put("attachment", mAttachment);
        postParams.put("action_links", mActionLinks);
        postParams.put("target_id", mTargetId);
        postParams.put("user_message_prompt", mMessagePrompt);

        try {
            loadURL(PUBLISH_URL, "POST", getParams, postParams);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void load() {
        loadExtendedPermissionPage();
    }
}
